﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;

namespace SAP
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        private GeneralFunctions GF;
        private LoginSession CurrentLoginSession;
        protected void Page_Load(object sender, EventArgs e)
        {
            SessionCheck();
            if (!IsPostBack)
            {
                try
                {

                    lblCompany.Text = CurrentLoginSession.CompanyName;
                    lblEmpID.Text = CurrentLoginSession.UserEmpID + " - " + CurrentLoginSession.UserName;
                    lblHotel.Text = CurrentLoginSession.HotelName;
                    lblManager.Text = CurrentLoginSession.ManagerEmpID + " - " + CurrentLoginSession.ManagerUserName;
                    lblOutlet.Text = CurrentLoginSession.OutletCode;
                    lblDepartment.Text = CurrentLoginSession.DeptName;


                    GetDefault df = new GetDefault();

                    if (CurrentLoginSession.UserEmpID == CurrentLoginSession.ManagerEmpID)
                    {
                        string constr = df.GetConnection(CurrentLoginSession.UserName);
                        if (constr != "")
                        {
                            ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "OKErrors",
                              "Main.setMasterMessage('Connecting to SAP.....FAILED' " + constr + ",'');", true);
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "OKErrors",
                              "Main.setMasterMessage('Connecting to SAP.....OK','');", true);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "OKErrors",
                                                           "Main.setMasterMessage('" + GeneralFunctions.UrlFullEncode(ex.ToString()) + "','');", true);

                    ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "CloseLoading",
                                                        "Dialog.hideLoader();", true);
                }
            }
        }

        public void SessionCheck()
        {

            if (Session["LoginSession"] != null)
            {
                this.CurrentLoginSession = (LoginSession)Session["LoginSession"];
                GF = new GeneralFunctions(CurrentLoginSession.UserName);
            }
            else
            {
                Response.Redirect("SessionErrorPage.aspx");
            }

        }    
    }
}